package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.auth.SaAdminCheckPermission;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteLevelPrivilegeOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.LevelPrivilegeDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegeCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegePageRequest;
import com.cskaoyan.wordmemorize.service.LevelPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author sgl
 * @version 1.0
 * @Date 2025/07/16
 */
@RestController
@RequestMapping("/admin/privilege")
public class AdminPrivilegeController {

    @Autowired
    LevelPrivilegeService levelPrivilegeService;

    @DeleteMapping("/batch")
    @SaAdminCheckPermission("admin:privilege:batchdelete")
    public Result deletePrivilegeBatch(@RequestBody BatchDeleteCommand batchDeleteCommand){
        levelPrivilegeService.batchDeleteLevelPrivilege(batchDeleteCommand);
        return Result.ok();
    }

    @DeleteMapping("/{id}")
    @SaAdminCheckPermission("admin:privilege:delete")
    public Result deletePrivilege(@PathVariable("id") String id){
        DeleteLevelPrivilegeOperateDTO deleteLevelDTO =
                levelPrivilegeService.deleteLevelPrivilege(Long.valueOf(id));
        return Result.ok();
    }


    @GetMapping("/list")
    @SaAdminCheckPermission("admin:privilege:search")
    public Result<PageDTO> getPrivilegeList( LevelPrivilegePageRequest levelPrivilegePageRequest){
        PageDTO<LevelPrivilegeDTO> levelPrivilegeList =
                levelPrivilegeService.getLevelPrivilegeList(levelPrivilegePageRequest);
        return Result.ok(levelPrivilegeList);
    }

    @PutMapping("")
    @SaAdminCheckPermission("admin:privilege:update")
    public Result updatePrivilege(@RequestBody LevelPrivilegeCommand levelPrivilegeCommand){
        levelPrivilegeService.updateLevelPrivilege(levelPrivilegeCommand);
        return Result.ok();
    }

    @PostMapping("")
    @SaAdminCheckPermission("admin:privilege:add")
    public Result addPrivilege(@RequestBody LevelPrivilegeCommand levelPrivilegeCommand){
        levelPrivilegeService.addLevelPrivilege(levelPrivilegeCommand);
        return Result.ok();
    }

}
